package com.aaa.service.impl;

import com.aaa.dao.ViewTestResultSasDao;
import com.aaa.entity.ViewTestResultSas;
import com.aaa.service.ViewTestResultSasService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @Author: WTH
* @Description: 
* @Date:2022-07-09 08:21
* @Params:  * @param null
* @return: 
*/
@Service
public class ViewTestResultSasServiceImpl implements ViewTestResultSasService {
    @Autowired
    private ViewTestResultSasDao viewTestResultSasDao;
    @Override
    public Page selectResultSas(ViewTestResultSas viewTestResultSas) {
        if (null!=viewTestResultSas.getLimit()){
            Page<ViewTestResultSas> page = PageHelper.startPage(viewTestResultSas.getPage(),viewTestResultSas.getLimit());
        }
        List<ViewTestResultSas> viewTestResultSas1 = viewTestResultSasDao.selectResultSas();
        Page tblTestersResultPage = (Page) viewTestResultSas1;
        return tblTestersResultPage;
    }

    @Override
    public List<ViewTestResultSas> selectResultOneSas(Integer testerId) {
        return viewTestResultSasDao.selectResultOneSas(testerId);
    }
  /**
  * @Author: WTH
  * @Description: 查询数据图
  * @Date:2022-07-09 08:21
  * @Params:  * @param null
  * @return: 
  */
    @Override
    public Map<String, Integer> seleTeseSasUser() {
        int normal =0;
        int mild=0;
        int moderate=0;
        int severe=0;
        List<ViewTestResultSas> viewSass = viewTestResultSasDao.selectSas();
        for (ViewTestResultSas viewSas : viewSass) {
            double one = viewSas.getOne();
            double two = viewSas.getTwo();
            double three = viewSas.getThree();
            double four = viewSas.getFour();
            double sum=(one+two*2+three*3+four*4);
            if (sum<=50){
                normal++;
            }else if (sum>=50 && sum<=59){
                mild++;
            }else if (sum>=60 && sum<=69){
                moderate++;
            }else {
                severe++;
            }
        }
        Map<String,Integer> map=new HashMap<>();
        map.put("normal",normal);
        map.put("mild",mild);
        map.put("moderate",moderate);
        map.put("severe",severe);
        return map;
    }
}
